package com.dotstone.chipism.activity;

import com.dotstone.chipism.R;
import com.dotstone.chipism.qrcode.EncodingUtils;
import com.dotstone.chipism.util.SPUtils;
import com.dotstone.chipism.util.ToastShow;
import com.dotstone.chipism.view.BlurBehind;
import com.dotstone.chipism.view.slidingfragmenu.BarUtils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class EarnMoneyActivity extends BaseActivity {
	private LinearLayout mBackL;
	private TextView tv_statusBar_mian;
	private Button mToUserB;
	private Button mToEngB;
	private String content; // 跳转过来的内容 用于生成二维码
	private ImageView mQrcodeImg;
	private Bitmap qrcodeBitmap;
	private String phone;

	@Override
	public void widgetClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_layout:
			finish();
			break;
		case R.id.to_user_btn:
//			qrcodeBitmap = showCaptrue(content);
//			mQrcodeImg.setImageBitmap(qrcodeBitmap);
			ToastShow.Show(getApplicationContext(), "公测阶段，功能尚未开放");
			break;
		case R.id.to_eng_btn:
			qrcodeBitmap = showCaptrue(content);
			mQrcodeImg.setImageBitmap(qrcodeBitmap);
			break;

		default:
			break;
		}
	}

	@Override
	public void initParms(Bundle parms) {
		// TODO Auto-generated method stub

	}

	@Override
	public View bindView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int bindLayout() {
		// TODO Auto-generated method stub
		return R.layout.activity_earn_money;
	}

	@Override
	public void initView(View view) {
		// TODO Auto-generated method stub
		BlurBehind.getInstance()
				// .withAlpha(100)
				// // .withFilterColor(Color.parseColor("#000000"))
				.setBackground(this);
		tv_statusBar_mian = $(R.id.tv_statusBar_mian);
		mBackL = $(R.id.back_layout);
		mToUserB = $(R.id.to_user_btn);
		mToEngB = $(R.id.to_eng_btn);
		mQrcodeImg = $(R.id.qrcode_img);
		boolVersion();
		mBackL.setOnClickListener(this);
		mToUserB.setOnClickListener(this);
		mToEngB.setOnClickListener(this);
		phone = (String) SPUtils.get(getApplicationContext(), "user_name", "");
		content = "http://goodtime-iot.com/apk/DotStone_Chipism.apk?handleType=3&userType=1&phone=" + phone + "&token="
				+ SPUtils.get(getApplicationContext(), "token", "");
		qrcodeBitmap = showCaptrue(content);
		mQrcodeImg.setImageBitmap(qrcodeBitmap);

	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doBusiness(Context mContext) {
		// TODO Auto-generated method stub

	}

	public void boolVersion() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

			Window window = getWindow();
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明导航栏
			// getWindow().addFlags(
			// WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
			// 改变titlebar的高度
			int statusbarHeight = BarUtils.getStatusBarHeight(this);
			RelativeLayout.LayoutParams layoutParams1 = (RelativeLayout.LayoutParams) tv_statusBar_mian
					.getLayoutParams();
			layoutParams1.height = statusbarHeight;
			tv_statusBar_mian.setLayoutParams(layoutParams1);
			tv_statusBar_mian.setVisibility(View.VISIBLE);

		} else {
			tv_statusBar_mian.setVisibility(View.GONE);
		}
	}

	private Bitmap showCaptrue(String content) {
		Bitmap bitmap = EncodingUtils.createQRCode(content, 460, 460,
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
		return bitmap;
	}

}
